clear all
graph set window fontface "Garamond"
set scheme white_tableau

**Fig. 1**
use "europe.dta",replace
capture graph drop *
graph bar (mean) com_by_1200,name(a) over(letter) asyvars  scheme(s1mono) ytitle("Share of towns with self-government by 1200")  ylabel(0 (0.2) 1) bar(2, color("black")) bar(1, color("gray")) bargap(25) legend(order(1 "No letter" 2 "Letter")) title("Europe", color(black))
use "italy.dta",replace
graph bar (mean) sg12,name(b) over(letter) asyvars  scheme(s1mono) ytitle("Share of towns with self-government by 1200") ylabel(0 (0.2) 1)  bar(2, color("black")) bar(1, color("gray")) bargap(25) legend(order(1 "No letter" 2 "Letter")) title("Northern Italy", color(black))
graph combine a b,graphregion(color(white))
graph export "f1.emf", replace

**Tab. 1**
use "italy.dta",replace
reg letter wars sea river caloricsuitmean road wpop elevmean elevstdev etruscan dist_rome dist_brenner_pass lpop bishop,b
use "europe.dta",replace
reg letter wars sea river soilquality elevation_m rugg10 drome rroad fup lpop bishop,b



**Fig. 4**
use "italy_tscs.dta",replace
bys cityid: egen ever_let=max(letter)
bys year ever_let: egen mean=mean(selfgov)
g m1=mean if ever_l==0
g m2=mean if ever_l==1
capture graph drop *
tw (line m1 year, lcolor(gray)) (line m2 year, lcolor(black)) if year<1201, name(a) xline(1073,lcolor(gray)) xline(1085, lcolor(gray)) graphregion(color(white)) xtitle("Year", size(medlarge)) ytitle("Share of towns with self-government", size(medlarge)) title("Italy", color(black)) legend(order(1 "No letter" 2 "Letter") region(lstyle(none) lcolor(white)) size(*1.2) symxsize(*.6) symysize(*.6) forcesize ring(0) position(11) colgap(tiny) row(1))

use "europe.dta",replace
merge 1:m indicator using "europe_tscs.dta"
bys year letter: egen mean=mean(commune)
g m1=mean if letter==1
g m2=mean if letter==0 
tw  (scatter m2 year, mcolor(gray) msize(vlarge)) (scatter m1 year, mcolor(black) )  if year<1201 & year>900, name(b) xline(1073,lcolor(gray)) xline(1085, lcolor(gray)) graphregion(color(white)) xtitle("Century", size(medlarge)) ytitle("Share of towns with self-government", size(medlarge)) title("Europe", color(black))  xlabel(1000 (100) 1200) legend(order(1 "No letter" 2 "Letter") region(lstyle(none) lcolor(white)) size(*1.2) symxsize(*.6) symysize(*.6) forcesize ring(0) position(11) colgap(tiny) row(1))

graph combine a b, graphregion(color(white))
graph export "f4.emf", replace


**Tab. 2**
use "europe.dta",replace
qui reg sgy_in_12 letter,r
eststo m1: margins, dydx(letter) post
qui reg sgy_in_12 letter sea river soilquality elevation_m rugg10 drome war lpop bishop rroad fup,r
eststo m2: margins, dydx(letter) post
qui reg sgy_in_12 letter sea river soilquality elevation_m rugg10 drome war lpop bishop rroad fup,r absorb(realm)
eststo m2a: margins, dydx(letter) post
use "italy.dta",replace
qui reg sgyears_in_12 letter ,r
eststo m3: margins, dydx(letter) post
qui reg sgyears_in_12 letter sea river wpop road caloricsuitmean elevmean elevstdev etruscan war dist_rome dist_brenner_pass lpop bishop ,r
eststo m4: margins, dydx(letter) post

esttab m1 m2 m2a m3 m4,se


**Fig. 5**
capture graph drop *
use "europe.dta",replace
g bis=0
recode bis (0=1) if bish==1 | arc==1
qui reg sgy letter##bis sea river soilquality elevation_m rugg10 drome war lpop rroad fup ,r
margins, dydx(letter) over(bis)
marginsplot, name(a) graphregion(color(white)) ytitle("Coefficient on letter", size(medlarge)) xtitle("Bishop", size(medlarge)) xscale(r(-0.2 1.2)) xlabel(0 "No" 1 "Yes") title("Europe", color(black)) recast(scatter) ciopts(lcolor(black)) plotopts(mcolor(black)) yline(0, lcolor(black) lpattern(dash))

use "italy.dta",replace
qui reg sgyears_in_12 letter##bishop sea river road wpop caloricsuitmean elevmean elevstdev etruscan war dist_rome dist_brenner_pass lpop  ,r
margins, dydx(letter) at(bishop=(1 2)) post
marginsplot, name(b) graphregion(color(white)) ytitle("Coefficient on letter", size(medlarge)) xtitle("Bishop", size(medlarge)) xscale(r(0.8 2.2)) xlabel(1 "No" 2 "Yes") title("Italy", color(black)) recast(scatter) ciopts(lcolor(black)) plotopts(mcolor(black)) yline(0, lcolor(black) lpattern(dash))
graph combine a b, graphregion(color(white))
graph export "f5.emf", replace

**Fig. 6**
use "europe.dta",replace
expand 11
g d=1
bys indicator: gen sum=sum(d)
replace sum=sum*100+700
g trans=0
recode trans (0=1) if first_com==sum
tab sum,g(dy)
g dt8=dy1*letter
g dt9=dy2*letter
g dt11=dy4*letter
g dt12=dy5*letter
g dt13=dy6*letter
g dt14=dy7*letter
g dt15=dy8*letter
g dt16=dy9*letter
g dt17=dy10*letter
g dt18=dy11*letter
g constant=1
capture graph drop *
reg trans dt8-dt9 constant dt11-dt18  sea##c.sum river##c.sum c.soilquality##c.sum c.elevation_m##c.sum c.rugg10##c.sum c.drome##c.sum c.war##c.sum rroad##c.sum c.fup##c.sum c.lpop##c.sum bishop##c.sum i.sum,absorb(indicator) cluster(indicator)
margins,dydx(dt8-dt9 constant dt11-dt18) noestimcheck
marginsplot,name(a) recast(scatter) xline(3.5,lpattern(dash) lcolor(gray)) xline(5,lpattern(dash) lcolor(gray)) xline(3,lcolor(black) lpattern(line)) yline(0,lcolor(black)) ytitle("Coefficient on letter",size(medlarge)) xtitle("Century",size(medlarge)) title("Europe",color(black)) xlabel(1 "800" 2 "900" 3 "1000" 4 "1100" 5 "1200" 6 "1300" 7 "1400" 8 "1500" 9 "1600" 10 "1700" 11 "1800") ciopts(lcolor(black)) plotopts(mcolor(black))

use "italy.dta",replace
expand 13
g d=1
bys cityid: gen sum=sum(d)
replace sum=975+sum*25

g temp=floor(yearof/25)*25

g trans=0
recode trans (0=1) if temp==sum
tab sum,g(ty)
foreach var of varlist ty1-ty13 {
g treat`var'=`var'*letter
}
g constant=1

reg trans treatty1-treatty2 constant treatty4-treatty13 road##c.sum c.wpop##c.sum sea#c.sum river#c.sum c.caloricsuitmean#c.sum c.elevmean#c.sum c.elevstdev#c.sum etruscan#c.sum c.war#c.sum c.dist_rome#c.sum c.dist_brenner_pass#c.sum c.lpop#c.sum c.bishop#c.sum i.sum,absorb(cityid) cluster(cityid)
margins,dydx(treatty1-treatty2 constant treatty4-treatty13) noestimcheck

marginsplot,name(b) recast(scatter) xline(4,lpattern(dash) lcolor(gray)) xline(9,lpattern(dash) lcolor(gray)) xline(3,lcolor(black) lpattern(line)) yline(0,lcolor(black)) ytitle("Coefficient on letter",size(medlarge)) xtitle("Period",size(medlarge)) title("Italy",color(black)) ciopts(lcolor(black)) plotopts(mcolor(black)) xlabel(1 "1000" 2 "1025" 3 "1050" 4 "1075" 5 "1100" 6 "1125" 7 "1150" 8 "1175" 9 "1200" 10 "1225" 11 "1250" 12 "1275" 13 "1300")

graph combine a b,graphregion(color(white))
graph export "event.emf", replace

**Fig. 7**
capture graph drop *
use "europe.dta",replace
g bis=0
recode bis (0=1) if bish==1 | arc==1
g wh=-1
qui reg sgy letter##c.dist_clun bis sea river rroad fup soilquality elevation_m rugg10 drome war lpop ,r
margins, dydx(letter) at(dist_clun=(0 (50) 2000))
marginsplot, name(a)  graphregion(color(white)) ytitle("Coefficient on letter", size(medlarge)) xtitle("Dist. neareast Cluniac monastery (km)", size(medlarge))   title("Europe", color(black)) recast(scatter) ciopts(lcolor(black)) plotopts(mcolor(black)) yline(0, lcolor(black) lpattern(dash)) legend(off) addplot(scatter wh dist_clun if dist_clu<2010,mcolor(black%25))

use "italy.dta",replace
g wh=-30
qui reg sgyears_in_12 letter##c.dist_clu road wpop bishop sea river caloricsuitmean elevmean elevstdev etruscan war dist_rome dist_brenner_pass lpop  ,r
margins, dydx(letter) at(dist_clun=(0 (50) 400)) post
marginsplot, name(b)  graphregion(color(white)) ytitle("Coefficient on letter", size(medlarge)) xtitle("Dist. neareast Cluniac monastery (km)", size(medlarge))   title("Northern Italy", color(black)) recast(scatter) ciopts(lcolor(black)) plotopts(mcolor(black)) yline(0, lcolor(black) lpattern(dash)) legend(off) addplot(scatter wh dist_clun if dist_clu<450,mcolor(black%25)) legend(off)
graph combine a b, graphregion(color(white))
graph export "cluny.emf", replace

**Fig. 8**
capture graph drop *
use "europe.dta",replace
qui reg sgy_in_12 i.lcat sea river soilquality elevation_m rugg10 drome war lpop bishop rroad fup,r
margins,over(lcat)
marginsplot,xlabel(0 "No letter" 1 "Letter mentioning investiture" 2 "Other letter") recast(scatter) plotopts(mcolor(black)) ciopts(lcolor(black)) xtitle("") ytitle("Centuries with self-government by 1200") title(Europe,color(black)) xscale(r(-0.2 2.2)) name(a)
use "italy.dta",replace
qui reg sgyears_in_12 i.lcat bishop sea river road wpop caloricsuitmean elevmean elevstdev etruscan war dist_rome dist_brenner_pass lpop  ,r
margins,over(lcat)
marginsplot,xlabel(0 "No letter" 1 "Letter mentioning investiture" 2 "Other letter") recast(scatter) plotopts(mcolor(black)) ciopts(lcolor(black)) xtitle("") ytitle("Years with self-government by 1200") title(Northern Italy,color(black)) xscale(r(-0.2 2.2)) name(b)
graph combine a b,graphregion(color(white))
graph export "content.emf",replace

************************
****Online Appendix*****
************************

**Fig. A1**
capture graph drop *
use "europe.dta",replace
geonear indicator latitu longit using "letter_loc.dta",n(id lat lon)
rename km dist_letter
tw (lowess sgy dist_letter,lcolor(black) lpattern(dash))  if dist_l<1000, graphregion(color(white)) xtitle("Dist. to letter (km)") title("Europe",color(black)) ytitle("Centuries of self-government in 1200") name(a) legend(off)
use "italy.dta",replace
geonear cityid lat lon using "letter_loc.dta",n(id lat lon)
rename km dist_letter
tw (lowess sgyears_in_1200 dist_letter,lcolor(black) lpattern(dash))  if dist_lett<1000, graphregion(color(white)) xtitle("Dist. to letter (km)") title("Italy",color(black)) ytitle("Years of self-government in 1200") name(b) legend(off)
graph combine a b, graphregion(color(white))
graph export "spatial.emf", replace

**Tab. A1**
use "europe.dta",replace
qui acreg sgy_in_12 letter,spatial latitude(lat) longitude(lon) dist(100)
eststo m1: margins, dydx(letter) post
qui acreg sgy_in_12 letter sea river soilquality elevation_m rugg10 drome war lpop rroad fup bishop ,spatial latitude(lat) longitude(lon) dist(100)
eststo m2: margins, dydx(letter) post
qui acreg sgy_in_12 letter sea rroad fup river soilquality elevation_m rugg10 drome war lpop bishop ,spatial latitude(lat) longitude(lon) dist(100) pfe1(realm)
eststo m2a: margins, dydx(letter) post
use "italy.dta",replace
qui acreg sgyears_in_12 letter ,spatial latitude(lat) longitude(lon) dist(100)
eststo m3: margins, dydx(letter) post
qui acreg sgyears_in_12 letter sea river road wpop caloricsuitmean elevmean elevstdev etruscan war dist_rome dist_brenner_pass lpop bishop ,spatial latitude(lat) longitude(lon) dist(100)
eststo m4: margins, dydx(letter) post

esttab m1 m2 m2a m3 m4,se

**Tab. A2**
xtset,clear
use "europe.dta",replace
g y=1000
xtset indicator y
spset indicator, coord(lon lat) coordsys(latlong)
spmatrix create idistance default, replace

spregress sgy_in_12 letter, gs2sls dvarlag(default) ivarlag(default: letter) heteroskedastic
spregress sgy_in_12 letter sea river  soilquality elevation_m rugg10 drome war lpop bishop rroa fup, gs2sls dvarlag(default) ivarlag(default: letter) heteroskedastic

spregress sgy_in_12 letter sea river rroad fup soilquality elevation_m rugg10 drome war lpop bishop i.realm, gs2sls dvarlag(default) ivarlag(default: letter) heteroskedastic

use "italy.dta",replace
spset cityid, coord(lon lat) coordsys(latlong)
spmatrix create idistance default, replace

spregress sgyears_in_12 letter, gs2sls dvarlag(default) ivarlag(default: letter) heteroskedastic
spregress sgyears_in_12 letter road sea wpop river caloricsuitmean elevmean elevstdev etruscan war dist_rome dist_brenner_pass lpop bishop, gs2sls dvarlag(default) ivarlag(default: letter) heteroskedastic


**Fig. A2*
capture graph drop *
use "europe.dta",replace
reg sgy_in_12 c.written##c.written##c.written,r
margins,at(written=(0 (1) 12))
marginsplot,xtitle(Number of letter recieved) recast(scatter) ytitle(Predicted number of centuries with self-government) ciopts(lcolor(black)) plotopts(mcolor(black)) name(a) title(Europe,color(black))
use "italy.dta",replace
reg sgyears_in_1200 c.written##c.written##c.written,r
margins,at(written=(0 (1) 5))
marginsplot,xtitle(Number of letter recieved) recast(scatter) ytitle(Predicted number of years with self-government) ciopts(lcolor(black)) plotopts(mcolor(black)) name(b) title(Northern Italy,color(black))
graph combine a b,graphregion(color(white)) rows(2) col(1)
graph export "nletter.emf", replace

**Tab. A3**
use "europe.dta",replace
drop if citypop==0
qui reg sgy_in_12 letter,r
eststo m1: margins, dydx(letter) post
qui reg sgy_in_12 letter sea river soilquality elevation_m rugg10 drome war lpop bishop rroad fup,r
eststo m2: margins, dydx(letter) post
qui reg sgy_in_12 letter sea river soilquality elevation_m rugg10 drome war lpop bishop rroad fup,r absorb(realm)
eststo m3: margins, dydx(letter) post
use "italy.dta",replace
drop if pop_1000==0
qui reg sgyears_in_12 letter ,r
eststo m4: margins, dydx(letter) post
qui reg sgyears_in_12 letter sea river wpop road caloricsuitmean elevmean elevstdev etruscan war dist_rome dist_brenner_pass lpop bishop ,r
eststo m5: margins, dydx(letter) post
esttab m1 m2 m3 m4 m5,se

**Tab. A4**
use "europe.dta",replace
qui reg sgy_in_12 letter dist_cluniac,r
eststo m1: margins, dydx(letter) post
qui reg sgy_in_12 dist_cluniac letter sea river soilquality elevation_m rugg10 drome war lpop bishop rroad fup,r
eststo m2: margins, dydx(letter) post
qui reg sgy_in_12 dist_cluniac letter sea river soilquality elevation_m rugg10 drome war lpop bishop rroad fup,r absorb(realm)
eststo m2a: margins, dydx(letter) post
use "italy.dta",replace
qui reg sgyears_in_12 letter dist_cluniac,r
eststo m3: margins, dydx(letter) post
qui reg sgyears_in_12 letter sea river wpop road caloricsuitmean elevmean elevstdev etruscan war dist_rome dist_brenner_pass lpop bishop dist_cluniac,r
eststo m4: margins, dydx(letter) post

esttab m1 m2 m2a m3 m4,se

**Table A5**
use "europe.dta",replace
qui reg sgy_in_12 letter,r
eststo m1: margins, dydx(letter) post
eststo m2: reg sgy_in_12 letter sea river soilquality elevation_m rugg10 drome war lpop bishop rroad fup,r
eststo m2a: reg sgy_in_12 letter sea river soilquality elevation_m rugg10 drome war lpop bishop rroad fup,r absorb(realm)
use "italy.dta",replace
qui reg sgyears_in_12 letter ,r
eststo m3: margins, dydx(letter) post
eststo m4: reg sgyears_in_12 letter sea river wpop road caloricsuitmean elevmean elevstdev etruscan war dist_rome dist_brenner_pass lpop bishop ,r

esttab m1 m2 m2a m3 m4,se









